﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WebService.Connect;
using System.Data.SqlClient;
using Model;
using System.Data;

namespace WebService.Datalayer
{
    public class DBStaff
    {
        Database db = new Database();
        SqlParameter[] listParameter;

        /// <summary>
        /// SelectStaffsAll
        /// </summary>
        /// <returns></returns>
        public DataSet SelectStaffsAll()
        {
            return db.GetDataset("sp_SelectStaffsAll");
        }

        /// <summary>
        /// SelectStaffsByAndStaffID
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public DataSet SelectStaffsByAndStaffID(Staffs obj)
        {
            listParameter = new SqlParameter[]
            {
                new SqlParameter("@StaffID", obj.StaffID),
            };
            return db.GetDataSetWithParameter("sp_SelectStaffsByAndStaffID", listParameter);
        }

        /// <summary>
        /// SelectStaffsByAndRoleID
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public DataSet SelectStaffsByAndRoleID(Staffs obj)
        {
            listParameter = new SqlParameter[]
            {
                new SqlParameter("@RoleID", obj.RoleID),
            };
            return db.GetDataSetWithParameter("sp_SelectStaffsByAndRoleID", listParameter);
        }

        /// <summary>
        /// DeleteStaff
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public int DeleteStaff(Staffs obj)
        {
            listParameter = new SqlParameter[]
            {
                new SqlParameter("@StaffID", obj.StaffID),
            };
            return db.ExcuteQueryWithParamater("sp_DeleteStaff", listParameter);
        }

        /// <summary>
        /// InsertStaff
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public int InsertStaff(Staffs obj)
        {
            listParameter = new SqlParameter[]
            {
                new SqlParameter("@StaffID", obj.StaffID),
                new SqlParameter("@RoleID", obj.RoleID),
                new SqlParameter("@UserName", obj.UserName),
                new SqlParameter("@Password", obj.Password),
                new SqlParameter("@StaffName", obj.StaffName),
                new SqlParameter("@Address", obj.Address),
                new SqlParameter("@BirthDate", obj.BirthDate),
                new SqlParameter("@Gender", obj.Gender),
                new SqlParameter("@NoNumber", obj.NoNumber),
                new SqlParameter("@PhoneNumber", obj.PhoneNumber),
                new SqlParameter("@Enable", obj.Enable),
                new SqlParameter("@StartWorkDate", obj.StartWorkDate),
                new SqlParameter("@EndWorkDate", obj.EndWorkDate),
                new SqlParameter("@CreateDate", obj.CreateDate),
                new SqlParameter("@IsDeleted", obj.IsDeleted),
                new SqlParameter("@IMEI", obj.IMEI),
            };
            return db.ExcuteQueryWithParamater("sp_InsertStaff", listParameter);
        }

        /// <summary>
        /// UpdateStaff
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public int UpdateStaff(Staffs obj)
        {
            listParameter = new SqlParameter[]
            {
                new SqlParameter("@StaffID", obj.StaffID),
                new SqlParameter("@RoleID", obj.RoleID),
                new SqlParameter("@UserName", obj.UserName),
                new SqlParameter("@Password", obj.Password),
                new SqlParameter("@StaffName", obj.StaffName),
                new SqlParameter("@Address", obj.Address),
                new SqlParameter("@BirthDate", obj.BirthDate),
                new SqlParameter("@Gender", obj.Gender),
                new SqlParameter("@NoNumber", obj.NoNumber),
                new SqlParameter("@PhoneNumber", obj.PhoneNumber),
                new SqlParameter("@Enable", obj.Enable),
                new SqlParameter("@StartWorkDate", obj.StartWorkDate),
                new SqlParameter("@EndWorkDate", obj.EndWorkDate),
                new SqlParameter("@CreateDate", obj.CreateDate),
                new SqlParameter("@IsDeleted", obj.IsDeleted),
                new SqlParameter("@IMEI", obj.IMEI),
            };
            return db.ExcuteQueryWithParamater("sp_UpdateStaff", listParameter);
        }

        /// <summary>
        /// SelectLogin
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public DataSet SelectLogin(string userName)
        {
            listParameter = new SqlParameter[]
            {
                new SqlParameter("@UserName", userName),
            };
            return db.GetDataSetWithParameter("sp_SelectLogin", listParameter);
        }

        /// <summary>
        /// SelectLogin
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public DataSet SelectLoginUser(string userName, string password)
        {
            listParameter = new SqlParameter[]
            {
                new SqlParameter("@UserName", userName),
                new SqlParameter("@Password", password),
            };
            return db.GetDataSetWithParameter("sp_SelectLoginUser", listParameter);
        }
    }
}